import axios from "axios";

// 定义接口
const endPoints = {
  test: "https://60b2643d62ab150017ae21de.mockapi.io/",
  prod: "https://prod.myapi.io/",
  staging: "https://staging.myapi.io/"
};

//创建axios 实例
const instance = axios.create({
  // 根据情况，改变baseURL值
  baseURL: endPoints.test,
  timeout: 30000,
  headers: { Authorization: "Bear mytoken" }
})

// 定义拦截器来处理所有请求。
instance.interceptors.response.use(
  (res) => {
    //为成功的请求添加特殊的逻辑
    return res;
  },
  (err) => {
    if (err.response.status === 403) {
      // do something to show login UI
    }
    return Promise.reject(err)
  }
);

export default instance